package com.android.baseconfig.data.http.okhttp.interceptor;


import com.android.baseconfig.data.http.okhttp.body.DownloadProgressResponseBody;
import com.android.baseconfig.data.http.okhttp.listener.DownloadProgressListener;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Response;

/**
 * Created by uuxia-mac on 16/7/3.
 * 下载进度及拦截器
 */
public class DownloadProgressInterceptor implements Interceptor {
    private DownloadProgressListener progressListener;

    public DownloadProgressInterceptor(DownloadProgressListener progressListener) {
        this.progressListener = progressListener;
    }

    @Override
    public Response intercept(Chain chain) throws IOException {
        Response originalResponse = chain.proceed(chain.request());
        return originalResponse.newBuilder()
                .body(new DownloadProgressResponseBody(originalResponse.body(), progressListener))
                .build();
    }
}
